// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var base = require("base");
	var databind = require("databind");
	var tools = require("tools");
//	var ctx3 = document.getElementById('chart3').getContext('2d');
//	var ctx2 = document.getElementById('chart2').getContext('2d');
//	var ctx8 = document.getElementById('chart8').getContext('2d');
	//	var _css = require("./login.css");
	var option_chart_2 = {};
	var option_chart_3 = {};
	var option_chart_4 = {};
	var option_chart_6 = {};
	var option_chart_7 = {};
	var option_chart_12 = {};
	var option_chart_14 = {};
	var option_chart_97 = {};
	var currentData;
	var geoCoordMap;

	var init = function() {
		initEvent();
	};
	
	var initEvent = function() {
		//前十大货品
		
//		inquireRankingDatas(1, 1);
		inquireRankingDatas(2, 2);
		inqurieReceivePaymentDetail();
		inqurieReceivePaymentDetail1();
		inquireManagerBordDetail();
		inqurieReceivePaymentListByArea();
		inquireLoanRankingDatas();
		getSalesFunnelReportforms();
		inquireFollowPersonRanking();
		inquireSevenDayEarnings();
		inquireEnterpriseLocation();
		inquireYestodayEarnings();
		
		setInterval(function(){
//			inquireRankingDatas(1, 1);
//			inquireRankingDatas(2, 2);
			inqurieReceivePaymentDetail();
//			inquireManagerBordDetail();
//			inquireEnterpriseArea();
		}, 30000);

		
	};
	
	//企业城市经纬度信息
	var inquireEnterpriseLocation = function() {
		base.fnAjax({
			action: "inquireEnterpriseLocation.json",
			async: true,
			nocode: true,
			oData: {
				type: 1
			}, //传递参数
			fnSuccess: function(data) {
					currentData = data.datas[0].currentData;
					geoCoordMap = data.datas[0].geoCoordMap;
					showArea();
				if(data.status == 200) {
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};
	
	var showArea = function (){
		var convertData = function (data) {
		    var res = [];
		    for (var i = 0; i < data.length; i++) {
		        var geoCoord = geoCoordMap[data[i].name];
		        if (geoCoord) {
		            res.push({
		                name: data[i].name,
		                value: geoCoord.concat(data[i].value)
		            });
		        }
		    }
		    return res;
		};
		
		option = {
		    backgroundColor: 'none',
		    title: {
		        x:'center',
		        textStyle: {
		            color: '#fff'
		        }
		    },
		    tooltip: {
		        trigger: 'item',
		        formatter: function (params) {
		            return params.name + ' : ' + params.value[2];
		        }
		    },
		    legend: {
		        
		    },
		    visualMap: {
		        min: 0,
		        max: 100000000,
		        calculable: true,
		//      orient: 'horizontal',
		//      align: 'top',
		        top:'50%',
		        left: '2%',
		        inRange: {
		            color: ['rgba(0,110,221,1)','rgba(255,241,168,1)','rgba(255,105,105,1)']
		        },
		        textStyle: {
		            color: '#fff'
		        }
		    },
		    geo: {
		    	type: 'map',
		        map: 'china',
		        geoIndex: 0,
		        roam:true,
		        zoom:1.2,
		        left:'14%',
		        label: {
		            emphasis: {
		                show: true
		            }
		        },
		        itemStyle: {
		            normal: {
		                areaColor: 'rgba(34, 88, 145,.9)',
		                borderColor: '#aaa'
		            },
		            emphasis: {
		                areaColor: '#2a333d'
		            }
		        }
		    },
		    series: [
		    	{
		            name: 'points',
		            type: 'scatter',
		            coordinateSystem: 'geo',
		            data: convertData(currentData),
		            symbolSize: 25,
		            label: {
		                normal: {
		                    show: false
		                },
		                emphasis: {
		                    show: false
		                }
		            },
		            itemStyle: {
		                emphasis: {
		                    borderColor: '#fff',
		                    borderWidth: 1
		                }
		            }
		        }
		    ]
		};
		if (option && typeof option === "object") {
		    myChart.setOption(option, true);
		}
	}
	
	var myChart97=function(d1, d2){
		var daydata=[];
		var teudata=d2;
		for(var i=0; i<d1.length ;i++){
			daydata.push(i);
//			teudata.push(i*100);
		}
	 	var chart_97 = echarts.init(document.getElementById("chart_97"));
		option_chart_97 = {
		    title: {
				show: true,
				top:5,
				left:5,
				textStyle:{
					color:"#fff",
					fontSize:15,
				},
				text: "近30日放款趋势"
			},
	//	    tooltip: {
	//	        trigger: 'axis'
	//	    },
		    legend: {
		    	show:false,
		    	textStyle:{
		    		color:"#fff",
		    	},
		    	top:12,
		    	right:5,
		        data:['放款额']
		    },
		    grid: {
		    	top:10,
		        left: '0',
		        right: '0',
		        bottom: 0,
		        containLabel: false
		    },
		    xAxis: {
		    	show:false,
		        type: 'category',
	//	        boundaryGap: false,
		        axisLine:{
	            	lineStyle:{
	            		color: '#999',
	            	},
	            },
		        data: daydata
		    },
		    yAxis: {
		    	show:false,
		        type: 'value',
		        splitLine:{
	            	show:true,
	            	lineStyle:{
	              	color: '#333',
	              }
	            },
		        axisLine:{
	            	lineStyle:{
	            		color: '#999',
	            	},
	            },
		    },
		    series: [
		        {
		            name:'放款额',
		            type:'bar',
		            label:{
		            	normal:{
		            		show:false,
		            		color:"#fff",
		            		position:"top",
		            	}
		            },
		            data:teudata
		        }
		    ]
		};
		chart_97.setOption(option_chart_97, true);
		setInterval(function () {
			var dele_day=daydata.shift();
			daydata.push(dele_day);
			var dele_teu=teudata.shift();
			teudata.push(dele_teu);
			chart_97.setOption({
				xAxis: {
		            data:daydata
		        },
		        series: [{
		            name:'放款额',
		            data: teudata
		        }]
			});
		},1000);
	}

	
	var inquireLoanRankingDatas = function() {
		base.fnAjax({
			action: "inquireLoanRankingDatas.json",
			async: true,
			nocode: true,
			oData: {
			}, //传递参数
			fnSuccess: function(data) {
				if(data.status == 200) {
					var d =[];
					var d1 = [];
					var d2 = [];
					var d3 = [];
					var d4 = [];
					var d5 = [];
					var d6 = [];
					$.each(data.datas, function() {
						var _this = this;
						d.push(_this.name);
						d1.push((_this.value1/10000).toFixed(2));
						d2.push((_this.value2/10000).toFixed(2));
						d3.push((_this.value3/10000).toFixed(2));
						d4.push((_this.value4/10000).toFixed(2));
						d5.push((_this.value5/10000).toFixed(2));
						d6.push((_this.value6/10000).toFixed(2));
						myChart4(d, d1, d2, d3, d4, d5, d6);
					});
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};
	
	var inquireManagerBordDetail = function() {
		base.fnAjax({
			action: "inquireManagerBordDetail.json",
			async: true,
			nocode: true,
			oData: {
			}, //传递参数
			fnSuccess: function(data) {
				if(data.status == 200) {
					$(".maindata1 .data_1 p").html((data.datas[0].enterpriseCreditLine/10000).toFixed(2));
					$(".maindata1 .data_1 .chart_9_title").html("直客额度(万元)");
					$(".maindata1 .data_2 p").html((data.datas[0].distributorsCreditLine/10000).toFixed(2));
					$(".maindata1 .data_2 .chart_9_title").html("分销商额度(万元)");
					$(".maindata1 .data_3 p").html((data.datas[0].enterpriseCreditLineAlready/10000).toFixed(2));
					$(".maindata1 .data_3 .chart_9_title").html("直客敞口额度(万元)");
					$(".maindata1 .data_4 p").html((data.datas[0].distributorsCreditLineAlready/10000).toFixed(2));
					$(".maindata1 .data_4 .chart_9_title").html("分销商敞口额度(万元)");
				
					$(".maindata2 .data_1 p").html((data.datas[0].loanAmount/10000).toFixed(2));
					$(".maindata2 .data_1 .chart_9_title").html("累计放款金额(万元)");
					$(".maindata2 .data_2 p").html((data.datas[0].receiveAmount/10000).toFixed(2));
					$(".maindata2 .data_2 .chart_9_title").html("累计还款金额(万元)");
					$(".maindata2 .data_3 p").html((data.datas[0].currentLoanAmount/10000).toFixed(2));
					$(".maindata2 .data_3 .chart_9_title").html("本月放款金额(万元)");
					$(".maindata2 .data_4 p").html((data.datas[0].currentReceiveAmount/10000).toFixed(2));
					$(".maindata2 .data_4 .chart_9_title").html("本月还款金额(万元)");
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};
	
	//销售漏斗项目金额与客户数量
	var getSalesFunnelReportforms = function() {
		base.fnAjax({
			action: "getSalesFunnelReportforms.json",
			async: true,
			nocode: true,
			oData: {
			}, //传递参数
			fnSuccess: function(data) {
				if(data.status == 200) {
					if (data.datas[0] != null && data.datas[0].rows.length > 0) {
						$(".list_3").html('<li><p class="area_2">阶段</p><p class="status_2">数量</p><p class="amount_2">金额</p></li>');
						var d1 = [];
						var d2 = [];
						$.each(data.datas[0].rows, function() {
							var _this = this;
							d1.push(_this.currentStatus);
							d2.push(_this.money);
							var str = '<li><p class="area_2">'+_this.currentStatus+'</p><p class="status_2">'+_this.totalSize+'</p><p class="amount_2">'+_this.money+'</p></li>'
							$(".list_3").append(str);
						});
						
						myChart14(d1, d2);
					}
					
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};
	
	var myChart3 = function(d1, d2){
		//chart_3 2017年各月存量金额（单位：万元）
		var chart_3 = echarts.init(document.getElementById("chart_3"));
		option_chart_3 = {
		    title: {
				show: true,
				top:10,
				textStyle:{
					color:"#fff",
					fontSize:15,
				},
				text: "2017年各月存量金额（单位：万元）"
			},
	//	    tooltip: {
	//	        trigger: 'axis'
	//	    },
		    legend: {
		    	textStyle:{
		    		color:"#fff",
		    	},
		    	top:12,
		    	right:5,
		        data:['存量']
		    },
		    grid: {
		    	top:50,
		        left: '2%',
		        right: '4%',
		        bottom: 10,
		        containLabel: true
		    },
		    xAxis: {
		        type: 'category',
	//	        boundaryGap: false,
		        axisLine:{
	            	lineStyle:{
	            		color: '#999',
	            	},
	            },
		        data: d1
		    },
		    yAxis: {
		        type: 'value',
		        splitLine:{
	            	show:true,
	            	lineStyle:{
	              	color: '#333',
	              }
	            },
		        axisLine:{
	            	lineStyle:{
	            		color: '#999',
	            	},
	            },
		    },
		    series: [
		        {
		            name:'存量',
		            type:'bar',
		            label:{
		            	normal:{
		            		show:true,
		            		color:"#fff",
		            		position:"top",
		            	}
		            },
		            data:d2
		        }
		    ]
		};
		chart_3.setOption(option_chart_3, true);
	};
	
	var myChart14 = function(d1, d2){
		//chart_14 销售漏斗项目金额与客户数量
		var chart_14 = echarts.init(document.getElementById("chart_14"));	
		option_chart_14 = {
			title: {
				
		    },
		    tooltip: {
		        
		    },
		    legend: {
		        
		    },
		    grid:{
		    	top:20,
		    	bottom:0,
		    	left:0,
		    	right:0,
		    },
		    xAxis: {
		    	show:false,
		        type: 'category',
		        boundaryGap: false,
		        data: d1
		    },
		    yAxis: {
		    	show:false,
		        type: 'value',
		        min:0,
		        max:'dataMax',
		    },
		    series: [
		        {
		            name:'成交',
		            type:'line',
		            smooth:false,
		            symbol: 'none',
	//	            stack: 'a',
					itemStyle: {
		                normal: {
		                    color: 'rgba(49,176,213,1)'
		                }
		            },
		            areaStyle: {
		                normal: {
		                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
		                        offset: 0,
		                        color: 'rgba(49,176,213,1)'
		                    }, {
		                        offset: 1,
		                        color: 'rgba(49,176,213,0)'
		                    }])
		                }
		            },
		            data: d2
		        }
		    ]
		};
		chart_14.setOption(option_chart_14, true);
	};
	
	var myChart6 = function(d1, d2, d3, d4){
		
		//chart_6 2017年各省市投放存量数据
		var chart_6 = echarts.init(document.getElementById("chart_6"));
		var chart_6_name = d1;
		option_chart_6 = {
			title: {
				show: true,
				left: '2%',
				bottom:10,
				textStyle:{
					color:"#fff",
					fontSize:15,
				},
				text: "2017年各省市投放存量数据"
			},
		    tooltip : {
		        trigger: 'axis',
		        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
		            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
		        }
		    },
		    legend: {
		    	textStyle:{
		    		color:"#fff",
		    	},
		    	orient: 'vertical',
		    	bottom: 20,
		    	right:5,
		        data:['投放', '回款', '存量']
		    },
		    grid: {
		    	top:10,
		        left: '2%',
		        right: '4%',
		        bottom: 20,
		        containLabel: true
		    },
		    xAxis : [
		        {
		        	show:false,
		            type : 'value',
		            splitLine:{
		            	show:true,
		            	lineStyle:{
		              	color: '#333',
		              }
		            },
		            axisLine:{
		            	lineStyle:{
		            		color: '#fff',
		            	},
		            },
		        }
		    ],
		    yAxis : [
		        {
		            type : 'category',
		            axisTick : {show: false},
		            axisLine:{
		            	lineStyle:{
		            		color: '#fff',
		            	},
		            },
		            
		            data : chart_6_name.reverse()
		        }
		    ],
		    series : [
		        {
		            name:'投放',
		            type:'bar',
		            label: {
		                normal: {
		                    show: true,
		                    position: 'inside'
		                }
		            },
		            data:d2
		        },
		        {
		            name:'回款',
		            type:'bar',
		            label: {
		                normal: {
		                    show: true
		                }
		            },
		            data:d3
		        },
		        {
		            name:'存量',
		            type:'bar',
		            label: {
		                normal: {
		                    show: true,
		                }
		            },
		            data:d4
		        }
		    ]
		};
		chart_6.setOption(option_chart_6, true);
	}

	var inquireRankingDatas = function(type, charNum) {
		base.fnAjax({
			action: "inquireRankingDatas.json",
			async: true,
			nocode: true,
			oData: {
				type: type
			}, //传递参数
			fnSuccess: function(data) {
				if(data.status == 200) {
//					data1 = data.datas;
					var d1 = [];
					var d2 = [];
					$.each(data.datas, function() {
						var _this = this;
						d1.push(_this.name);
						d2.push(_this.value);
					});
					if (charNum == 1) {
						myChart7(d1.slice(0, 10), d2.slice(0, 10), cr1, cr2);
					} else if (charNum == 2) {
						myChart7(d1.slice(0, 10), d2.slice(0, 10));
					}
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};
	
	
	var inqurieReceivePaymentDetail = function() {
		base.fnAjax({
			action: "inqurieReceivePaymentDetail.json",
			async: true,
			nocode: true,
			oData: {
				type: 1
			}, //传递参数
			fnSuccess: function(data) {
					var datas1 = data.datas[0].dates;
					var datas2 = data.datas[0].receives;
					var datas3 = data.datas[0].payments;
					var datas4 = data.datas[0].stock;
					myChart2(datas1, datas2, datas3);
					myChart3(datas1, datas4);
				if(data.status == 200) {
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};
	
	var inqurieReceivePaymentDetail1 = function() {
		base.fnAjax({
			action: "inqurieReceivePaymentDetail.json",
			async: true,
			nocode: true,
			oData: {
				type: 4
			}, //传递参数
			fnSuccess: function(data) {
					var datas1 = data.datas[0].dates;
					var datas2 = data.datas[0].receives;
					var datas3 = data.datas[0].payments;
					var datas4 = data.datas[0].stock;
					
					myChart97(datas1, datas3);
				if(data.status == 200) {
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};
	
	var inqurieReceivePaymentListByArea = function() {
		base.fnAjax({
			action: "inqurieReceivePaymentListByArea.json",
			async: true,
			nocode: true,
			oData: {
			}, //传递参数
			fnSuccess: function(data) {
				if(data.status == 200) {
					var datas1 = data.datas[0].dates;
					var datas2 = data.datas[0].receives;
					var datas3 = data.datas[0].payments;
					var datas4 = data.datas[0].stock;
					myChart6(datas1, datas2, datas3, datas4);
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};
	
	var inquireYestodayEarnings = function() {
		base.fnAjax({
			action: "inquireYestodayEarnings.json",
			async: true,
			nocode: true,
			oData: {
			}, //传递参数
			fnSuccess: function(data) {
				if(data.status == 200) {
					$(".earningSum").html(data.datas[0].sum);
					$(".earning2").html(tools.formatCurrency(data.datas[0].value2/10000));
					$(".earning6").html(tools.formatCurrency(data.datas[0].value6/10000));
				} else { 
					layer.msg(data.message);
				}
			}
		});_this.name
	};
	
	var inquireFollowPersonRanking = function() {
		base.fnAjax({
			action: "inquireFollowPersonRanking.json",
			async: true,
			nocode: true,
			oData: {
			}, //传递参数
			fnSuccess: function(data) {
				if(data.status == 200) {
					var d1 = [];
					var d2 = [];
					var cr = ['rgba(194,53,49,1)'];
					$.each(data.datas, function() {
						var _this = this;
						d1.push(_this.name);
						var d = {
							name: _this.name,
							value: _this.value
						}
						d2.push(d);
						cr.push(getRandomColor(1));
					});
					myChart12(d1, d2, cr);
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};
	
	var inquireSevenDayEarnings = function() {
		base.fnAjax({
			action: "inquireSevenDayEarnings.json",
			async: true,
			nocode: true,
			oData: {
			}, //传递参数
			fnSuccess: function(data) {
				if(data.status == 200) {
					$(".slideblk .stock").html(tools.formatCurrency((data.datas[0].value1/10000).toFixed(2)));
					$(".stocblk .stock").html(tools.formatCurrency((data.datas[0].value2/10000).toFixed(2)));
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};
	
	var myChart12 = function(d1, d2, cr){
		//chart_12 2017年业务经理收益贡献比
		var chart_12 = echarts.init(document.getElementById("chart_12"));
		option_chart_12 = {
		    title : {
			    	show : true,
			    	left: 'center',
					top:5,
					textStyle:{
						color:"#fff",
						fontSize:15,
					},
					text: "2017年业务经理收益贡献比"
			    },
		    legend: {
		    	textStyle:{
		    		color:"#fff",
		    	},
		    	bottom: 5,
	            left: 'center',
	            data: d1,
		    },
		    tooltip : {
		        trigger: 'item',
		    },
		    toolbox: {
		        show : false,
		    },
		    calculable : false,
		    series : [
		        {
		            type:'pie',
		            radius : ['0', '70%'],
		            center : ['50%', '45%'],
	//	            roseType : 'radius',
		            label: {
		                normal: {
		                    show: false
		                },
		            },
//		            color:['rgba(194,53,49,1)','#0193cb','#ce942b','#92e1ff','#61a0a8','#0193cb'],
		            color:cr,
		            data:d2
		        }
		    ]
		};
		chart_12.setOption(option_chart_12, true);
	}
	
	
	var myChart2 = function(datas, payments, receives){
		//chart_2 月投放量与回款量
		var chart_2 = echarts.init(document.getElementById("chart_2"));
		option_chart_2 = {
			title: {
				show: true,
				top:10,
				textStyle:{
					color:"#fff",
					fontSize:15,
				},
				text: "2017年月投放量与回款量（单位：万元）"
			},
	//	    tooltip: {
	//	        trigger: 'axis'
	//	    },
		    legend: {
		    	textStyle:{
		    		color:"#fff",
		    	},
		    	top:12,
		    	right:5,
		        data:['投放','回款']
		    },
		    grid: {
		    	top:70,
		        left: '2%',
		        right: '4%',
		        bottom: 20,
		        containLabel: true
		    },
		    xAxis: {
		        type: 'category',
		        boundaryGap: false,
		        axisLine:{
	            	lineStyle:{
	            		color: '#999',
	            	},
	            },
		        data: datas
		    },
		    yAxis: {
		        type: 'value',
		        splitLine:{
	            	show:true,
	            	lineStyle:{
	              	color: '#333',
	              }
	            },
		        axisLine:{
	            	lineStyle:{
	            		color: '#999',
	            	},
	            },
		    },
		    series: [
		        {
		            name:'回款',
		            type:'line',
		            itemStyle: {
		            	normal: {
		            		color:'#d48265',
		            	}
		            },
		            label:{
		            	normal:{
		            		show:true,
		            		color:"#fff",
		            		position:"bottom",
		            	}
		            },
	//	            stack: '总量',
		            data:receives
		        },
		        {
		            name:'投放',
		            type:'line',
		            itemStyle: {
		            	normal: {
		            		color:'#91c7ae',
		            	}
		            },
		            label:{
		            	normal:{
		            		show:true,
		            		color:"#fff",
		            		position:"top",
		            	}
		            },
	//	            stack: '总量',
		            data:payments
		        }
		    ]
		};
		chart_2.setOption(option_chart_2, true);
	}
	
	var myChart4 = function(d, d1, d2, d3, d4, d5, d6){
		//chart_4 2017年各业务类型投放增长量
		var chart_4 = echarts.init(document.getElementById("chart_4"));
		option_chart_4 = {
		    title: {
				show: true,
				top:10,
				textStyle:{
					color:"#fff",
					fontSize:15,
				},
				text: "2017年各业务类型投放增长量（单位：万元）"
			},
	//	    tooltip: {
	//	        trigger: 'axis'
	//	    },
		    legend: {
		    	textStyle:{
		    		color:"#fff",
		    	},
		    	bottom:5,
		    	left: 'center',
		        data:["舱单代采", "舱单质押", "仓储质押", "保理融资", "代理采购", "代理销售"]
		    },
		    grid: {
		    	top:50,
		        left: '2%',
		        right: '4%',
		        bottom: 30,
		        containLabel: true
		    },
		    xAxis: {
		    	type: 'category',
	//	        boundaryGap: false,
		        axisLine:{
	            	lineStyle:{
	            		color: '#999',
	            	},
	            },
		        data: d1
		    },
		    yAxis: {
		        type: 'value',
		        splitLine:{
	            	show:true,
	            	lineStyle:{
	              	color: '#333',
	              }
	            },
		        axisLine:{
	            	lineStyle:{
	            		color: '#999',
	            	},
	            },
		    },
		    series: [
		        {
		            name:'舱单代采',
		            type:'line',
	//	            stack: '总量',
					label:{
		            	normal:{
		            		show:true,
		            		color:"#fff",
		            		position:"top",
		            	}
		            },
		            data:d1
		        },
		        {
		            name:'舱单质押',
		            type:'line',
		            label:{
		            	normal:{
		            		show:true,
		            		color:"#fff",
		            		position:"top",
		            	}
		            },
	//	            stack: '总量',
		            data:d2
		        },
		        {
		            name:'仓储质押',
		            type:'line',
		            label:{
		            	normal:{
		            		show:true,
		            		color:"#fff",
		            		position:"top",
		            	}
		            },
	//	            stack: '总量',
		            data:d3
		        },
		        {
		            name:'保理融资',
		            type:'line',
		            label:{
		            	normal:{
		            		show:true,
		            		color:"#fff",
		            		position:"top",
		            	}
		            },
	//	            stack: '总量',
		            data:d4
		        },
		        {
		            name:'代理采购',
		            type:'line',
		            label:{
		            	normal:{
		            		show:true,
		            		color:"#fff",
		            		position:"top",
		            	}
		            },
	//	            stack: '总量',
		            data:d5
		        },
		        {
		            name:'代理销售',
		            type:'line',
		            label:{
		            	normal:{
		            		show:true,
		            		color:"#fff",
		            		position:"top",
		            	}
		            },
	//	            stack: '总量',
		            data:d6
		        }
		    ]
		};
		chart_4.setOption(option_chart_4, true);
	};
	

	var inquireEnterpriseFinanceSummaryPageList = function() {
		//loading层
		base.fnAjax({
			action: "inquireEnterpriseFinanceSummaryPageList.json",
			async: true,
			nocode: true,
			oData: {
				pageSize: 1000
			}, //传递参数
			fnSuccess: function(data) {
				if(data.status == 200) {
					juicer.register("formatCurrency", tools.formatCurrency);
					var tpl = $(".summaryTpl").html();
					var html = juicer(tpl, data);
					$(".summaryTab tbody").html(html);
					$('.summaryTab').stickySort({ 
						sortable: true
					});
					layer.close(ii);
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};
	
	//前十大客户
	var myChart7 = function(data1, data2){
		//chart_7 前十大客户融资金额排名	
		var chart_7 = echarts.init(document.getElementById("chart_7"));
		var legenddata = data1;
		var chart_7_val = data2;
		var chart_7_data = [];
		$(function(){
			for (var i = 0; i < legenddata.length; i++) {
				var aa = {'value':chart_7_val[i],'name':legenddata[i]};
				chart_7_data.push(aa);
			};
			option_chart_7 = {
			    title : {
			    	show : true,
			    	left: 'center',
					bottom:10,
					textStyle:{
						color:"#fff",
						fontSize:15,
					},
					text: "前十大客户融资金额排名"
			    },
			    tooltip : {
			        trigger: 'item',
			    },
			    legend: {
			    	textStyle:{
			    		color:"#fff",
			    	},
			    	orient: 'vertical',
			    	top: 15,
		            left: 0,
		            data: legenddata,
		            formatter: function (name) {
						var index = 0;
		                legenddata.forEach(function(value,i){
		                    if(value == name){
		                        index = i;
		                    }
		                });
		                return name + "    " + chart_7_val[index] + "元";
		            }
			    },
			    toolbox: {
			        show : false,
			    },
			    calculable : false,
			    series : [
			        {
		//	            name:'半径模式',
			            type:'pie',
			            radius : ['40%', '60%'],
			            center : ['70%', '45%'],
		//	            roseType : 'radius',
			            tooltip : {
					        trigger: 'item',
					    },
			            label: {
			                normal: {
			                    show: false
			                },
			                emphasis: {
			                    show: false
			                }
			            },
			            lableLine: {
			                normal: {
			                    show: false
			                },
			                emphasis: {
			                    show: false
			                }
			            },
		//	            color:['rgba(194,53,49,1)','#0193cb','#ce942b','#92e1ff','#61a0a8','#0193cb'],
			            data:chart_7_data
			        }
			    ]
			};
			chart_7.setOption(option_chart_7, true);
		});
	};
	
	var myChart8 = function(d1, d2, cr1, cr2) {
		new Chart(ctx8, {
			type: 'pie',
			data: {
				labels: d1,
				datasets: [{
					data: d2,
					backgroundColor: cr1,
					borderColor: cr2,
					borderWidth: '2',
					pointRadius: '10',
					hoverBorderWidth: '0',
					hoverBorderColor: ['#2185da', '#2185da', '#2185da'],
				}],
			},
			options: {
				legend: {
					position: 'bottom',
					display: true,
				},
			},
		});
	}
	
	var testSummayry = function() {
		base.fnAjax({
			action: "testSummayry.json",
			async: true,
			oData: {
				pageSize: 1000
			}, //传递参数
			fnSuccess: function(data) {
				if(data.status == 200) {
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};
	
	var showChart1 = function(d, d1) {
		// 基于准备好的dom，初始化echarts实例
		var myChart1 = echarts.init(document.getElementById('main1'));
		// 指定图表的配置项和数据
		//app.title = '嵌套环形图';

		var option = {
			title: {
				text: '',
				subtext: '一润供应链',
				x: 'left'
			},
			tooltip: {
				trigger: 'item',
				formatter: "{a} <br/>{b} : {c} ({d}%)"
			},
			legend: {
				 orient: 'horizontal',
		         x: 'left',
		         y:'bottom',		
		        data:d1
		    },
			toolbox: {
				show: true,
				feature: {
					mark: {
						show: true
					},
					dataView: {
						show: true,
						readOnly: false
					},
					magicType: {
						show: true,
						type: ['pie', 'funnel']
					},
					restore: {
						show: true
					},
					saveAsImage: {
						show: true
					}
				}
			},
			calculable: true,
			series: [{
				name: '访问来源',
				type: 'pie',
				radius: ['30%', '50%'],
				avoidLabelOverlap: false,
				center: ['50%', '60%'],
				data: d,
				itemStyle: {
					emphasis: {
						shadowBlur: 10,
						shadowOffsetX: 0,
						shadowColor: 'rgba(0, 0, 0, 0.5)'
					}
				}
			}]
		};

		// 使用刚指定的配置项和数据显示图表。
		myChart1.setOption(option);
		// 处理点击事件并且跳转到相应的百度搜索页面
		myChart1.on('click', function(params) {
			//window.open('https://www.baidu.com/s?wd=' + encodeURIComponent(params.name));
			window.open('../rankingDetail/rankingDetail.html?goodsName=' + encodeURI(encodeURI(params.name)) + '&bulkstockInfoId=' + params.data.detailId);
		});
	};

	var showChart2 = function(d, d1) {
		// 基于准备好的dom，初始化echarts实例
		var myChart2 = echarts.init(document.getElementById('main0'));
		// 指定图表的配置项和数据
		//app.title = '嵌套环形图';

		var option = {
			title: {
				text: '',
				subtext: '一润供应链',
				x: 'left'
			},
			tooltip: {
				trigger: 'item',
				formatter: "{a} <br/>{b} : {c} ({d}%)"
			},

			toolbox: {
				show: true,
				feature: {
					mark: {
						show: true
					},
					dataView: {
						show: true,
						readOnly: false
					},
					magicType: {
						show: true,
						type: ['pie', 'funnel']
					},
					restore: {
						show: true
					},
					saveAsImage: {
						show: true
					}
				}
			},
			legend: {
				 orient: 'horizontal',
		         x: 'left',
		         y:'bottom',		
		        data:d1
		    },
			calculable: true,
			series: [{
				name: '融资金额',
				type: 'pie',
				radius: ['30%', '50%'],
				avoidLabelOverlap: false,
				center: ['50%', '60%'],
				data: d,
				itemStyle: {
					emphasis: {
						shadowBlur: 10,
						shadowOffsetX: 0,
						shadowColor: 'rgba(0, 0, 0, 0.5)'
					}
				}
			}]
		};

		// 使用刚指定的配置项和数据显示图表。
		myChart2.setOption(option);
		// 处理点击事件并且跳转到相应的百度搜索页面
		myChart2.on('click', function(params) {
			//window.open('https://www.baidu.com/s?wd=' + encodeURIComponent(params.name));
			window.open('../rankingDetail/rankingDetail1.html?customerName=' + encodeURI(encodeURI(params.name)) + '&enterpriseId=' + params.data.detailId);
		});
	};

	var showChart3 = function() {
		// 基于准备好的dom，初始化echarts实例
		var myChart2 = echarts.init(document.getElementById('main2'));

		// 指定图表的配置项和数据
		//app.title = '嵌套环形图';

		var option = {
			color: ['#3398DB'],
			title: {
				text: '客户违约排行',
				subtext: '一润供应链'
			},
			tooltip: {
				trigger: 'axis'
			},
			legend: {
				data: ['违约']
			},
			tooltip: {
				trigger: 'axis',
				axisPointer: { // 坐标轴指示器，坐标轴触发有效
					type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
				}
			},
			grid: {
				left: '3%',
				right: '4%',
				bottom: '3%',
				containLabel: true
			},
			toolbox: {
				show: true,
				feature: {
					dataView: {
						show: true,
						readOnly: false
					},
					magicType: {
						show: true,
						type: ['line', 'bar']
					},
					restore: {
						show: true
					},
					saveAsImage: {
						show: true
					}
				}
			},
			calculable: true,
			xAxis: [{
				type: 'category',
				data: ['浙江永福', '福建鑫泰', '江苏有限', '上海永新', '南京化工', '广州南方', '海南永康', '天津豪迈'],
				axisTick: {
					alignWithLabel: true
				}
			}],
			yAxis: [{
				type: 'value'
			}],
			series: [{
				name: '收款',
				type: 'bar',
				barWidth: '60%',
				label: {
					normal: {
						show: true,
						position: 'inside'
					}
				},
				data: [0, 0, 0, 0, ,0, 0, 0, 0]
			}]
		};

		// 使用刚指定的配置项和数据显示图表。
		myChart2.setOption(option);
	}
	
	var getRandomColor = function(l) {
		var w = 255;
		Math.random()*255
		var color = "rgba("+parseInt(Math.random()*255, 10)+","+parseInt(Math.random()*255, 10)+","+parseInt(Math.random()*255, 10)+","+l+")";
		return color;
	}

	return {
		init: init
	};
});